package com.chengqs.controller;

import com.chengqs.pojo.DTO.MoviePageQueryDTO;
import com.chengqs.pojo.R;
import com.chengqs.pojo.entity.Movie;
import com.chengqs.service.MovieService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/movies")
public class MovieController {

    @Autowired
    private MovieService movieService;

    @GetMapping("/page")
    public R page(MoviePageQueryDTO pageQuery){
        Page<Movie> movies = movieService.pageQuery(pageQuery);
        HashMap<Object, Object> result = new HashMap<>();
        result.put("total",movies.getTotal());
        result.put("list",movies.getResult());
        return R.success(result);
    }

    @GetMapping("/{id}")
    public R getMovieById(@PathVariable Integer id){
        return R.success(movieService.getMovieById(id));
    }
}
